package com.lb.jwitter.action;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.Collection;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.lb.jwitter.service.ConditionReport;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblDKMHDotDKNhom;
import com.lb.jwitter.service.TblDKMHDotDKNhomService;
import com.lb.jwitter.service.TblDKMHDotDK;
import com.lb.jwitter.service.TblDKMHDotDKService;

import com.lb.jwitter.service.TblDKMHDotDKHocVienChiTiet;
import com.lb.jwitter.service.TblDKMHDotDKHocVienChiTietService;

import com.lb.jwitter.service.TblDKMHDotDKHocVien;
import com.lb.jwitter.service.TblDKMHDotDKHocVienService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblDKMHDotDKNhomEditFormAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private int id; 
    public int getId() { return id; }

    public void setId(int id) { this.id = id; }

    private Date today; 
    public Date getToday() { return new Date(); } 

    private TblDKMHDotDKNhom tblDKMHDotDKNhom; 
    public TblDKMHDotDKNhom getTblDKMHDotDKNhom() { 
        return tblDKMHDotDKNhom; 
    } 
    private Collection<TblDKMHDotDKNhom> tblDKMHDotDKNhoms; 
    public Collection<TblDKMHDotDKNhom>  getTblDKMHDotDKNhoms() {
         return tblDKMHDotDKNhoms; 
      } 

    private TblDKMHDotDKNhomService tblDKMHDotDKNhomService; 

    private Collection<TblDKMHDotDK> tblDKMHDotDKs; 
    public Collection<TblDKMHDotDK>  getTblDKMHDotDKs(){ 
              return tblDKMHDotDKs; 
     } 

    private TblDKMHDotDKService tblDKMHDotDKService; 

    private Collection<TblDKMHDotDKHocVienChiTiet> tblDKMHDotDKHocVienChiTiets; 
    public Collection<TblDKMHDotDKHocVienChiTiet>  getTblDKMHDotDKHocVienChiTiets(){ 
              return tblDKMHDotDKHocVienChiTiets; 
     } 

    private TblDKMHDotDKHocVienChiTietService tblDKMHDotDKHocVienChiTietService; 

    private Collection<TblDKMHDotDKHocVien> tblDKMHDotDKHocViens; 
    public Collection<TblDKMHDotDKHocVien>  getTblDKMHDotDKHocViens(){ 
              return tblDKMHDotDKHocViens; 
     } 

    private TblDKMHDotDKHocVienService tblDKMHDotDKHocVienService; 

    private int pageSizeTblDKMHDotDKHocVienChiTiet; 
    public int getPageSizeTblDKMHDotDKHocVienChiTiet() {
        return pageSizeTblDKMHDotDKHocVienChiTiet;
 }

    public void setPageSizeTblDKMHDotDKHocVienChiTiet(int pageSizeTblDKMHDotDKHocVienChiTiet) {        this.pageSizeTblDKMHDotDKHocVienChiTiet = pageSizeTblDKMHDotDKHocVienChiTiet; }

    private int pageTblDKMHDotDKHocVienChiTiet; 
    public int getPageTblDKMHDotDKHocVienChiTiet() { return pageTblDKMHDotDKHocVienChiTiet; }

    public void setPageTblDKMHDotDKHocVienChiTiet(int pageTblDKMHDotDKHocVienChiTiet) { this.pageTblDKMHDotDKHocVienChiTiet = pageTblDKMHDotDKHocVienChiTiet; }

    private int pagesTblDKMHDotDKHocVienChiTiet; 
    public int getPagesTblDKMHDotDKHocVienChiTiet() { return pagesTblDKMHDotDKHocVienChiTiet; }

    public void setPagesTblDKMHDotDKHocVienChiTiet(int pagesTblDKMHDotDKHocVienChiTiet) { this.pagesTblDKMHDotDKHocVienChiTiet = pagesTblDKMHDotDKHocVienChiTiet; }

    private String dataStringTblDKMHDotDKHocVienChiTiet; 
    public String getDataStringTblDKMHDotDKHocVienChiTiet() { return dataStringTblDKMHDotDKHocVienChiTiet; }

  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
       try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_DKMH_DotDK_Nhom", "sua")){ 
        return "noprivilege"; 
    }
        tblDKMHDotDKNhomService = (TblDKMHDotDKNhomService) context.getBean("tbl_DKMH_DotDK_NhomClient"); 
        tblDKMHDotDKService = (TblDKMHDotDKService) context.getBean("tbl_DKMH_DotDKClient"); 

        tblDKMHDotDKHocVienChiTietService = (TblDKMHDotDKHocVienChiTietService) context.getBean("tbl_DKMH_DotDK_HocVien_ChiTietClient"); 

        tblDKMHDotDKHocVienService = (TblDKMHDotDKHocVienService) context.getBean("tbl_DKMH_DotDK_HocVienClient"); 

        tblDKMHDotDKNhom = tblDKMHDotDKNhomService.gettblDKMHDotDKNhom(new Long(id)); 
        tblDKMHDotDKs = tblDKMHDotDKService.findAlltblDKMHDotDK(0, 0);

   if (pageSize == 0) 
   { 
       pageSize = 20; 
   } 
   if (page == 0) 
   { 
       page = 1; 
   } 
   List<ConditionReport> cons = new ArrayList<ConditionReport>(); 
cons.clear(); 
      tblDKMHDotDKHocViens =       tblDKMHDotDKHocVienService.findAlltblDKMHDotDKHocVien(0, 0); 
cons.clear(); 
   if (id != 0) 
   { 
       ConditionReport con = new ConditionReport(); 
       con.setCol("nhomDKId.id"); 
       con.setValue1(new Long(id)); 
       con.setOperator("eq"); 
       cons.add(con); 
   } 
   tblDKMHDotDKHocVienChiTiets = tblDKMHDotDKHocVienChiTietService.findtblDKMHDotDKHocVienChiTietByCondition(cons, pageSize, page); 
    pageTblDKMHDotDKHocVienChiTiet = page; 
    pageSizeTblDKMHDotDKHocVienChiTiet = pageSize; 
 
    pagesTblDKMHDotDKHocVienChiTiet =tblDKMHDotDKHocVienChiTietService.counttblDKMHDotDKHocVienChiTietByCondition(cons)/pageSizeTblDKMHDotDKHocVienChiTiet + 1; 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
      System.out.println("Loi EditForm tbl_DKMH_DotDK_Nhom Action"); 
     e.printStackTrace(); 
    return Action.ERROR; 
 } 
 } 
 } 
 
